<?php
/*********************************************************************************
* Filename: team_creation.php
* 
* This PHP script validates input recieved from the user for creating a team,
* and if the input is valid inserts a new entry into the TEAMS table in the 
* database for the selected league.
*
*
* Author: Caleb Goff
* Date Created: 10/10/2009
**********************************************************************************/

//The common.php file contains 
include_once "common.php";

echo "$header_open";
echo "$css_create";
echo "$js_create_team";
echo "$header_close";

?>

<body onload="postLoad();">

<!-- Define the incorrect login information pop up div. -->
<div id="popupBadPwdMatch" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Team passwords do not match!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadPwdMatch')">
</div>

<div id="popupBadEmail" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Invalid team email provided!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadEmail')">
</div>

<div id="popupBadTeamName" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Invalid team name provided!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadTeamName')">
</div>

<div id="popupBadLeaguePwd" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Invalid league password provided!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadLeaguePwd')">
</div>

<div id="popupBadTeamPwd" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Invalid input for team password!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadTeamPwd')">
</div>

<div id="popupTeamExists" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	A team by that name already exists!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupTeamExists')">
</div>

<div id="popupEmailExists" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	A team is already using that email address!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupEmailExists')">
</div>

<div id="popupBadLeague" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Please select a league from the drop-down list!<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupBadLeague')">
</div>

<div id="popupTeamSuccess" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Success!</b></u><br><br>
	Your team has been successfully created! Check you email for validation link.<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupTeamSuccess')">;
</div>

<div id="popupInvaludInput" style="border:2px solid black; background-color:#C0C0C0; padding:5px; font-size:150%; text-align:center; display:none;">
	<b><u>Alert!</b></u><br><br>
	Only alphanumeric characters are allowed, except the @ and .<br><br>	
	<input type="button" value="OK" onClick="Popup.hide('popupInvaludInput')">
</div>
<!-- End defining popup divs -->

	<div id="wrapper">
		<div id="inner">
			<div id="masthead">
				<h1>
				</h1>
				<ul>
					<?php 
						echo"$g_nav_bar";
					?>
				</ul>
			</div>

			<div id="all_content">
				<h2>Create a Team</h2>
				Ready to hit the ice with Fantasy Broomball? If you have recieved a league invitation you can use 
                the supplied league password to create your team and join the league!
			    <br><br>
			    <i>Some things to keep in mind...</i>
			    <ul>
                    <li>- Only alphanumeric characters are allowed</li>
                </ul>
				<h2>League Information</h2>
				<div id="info_box">
					<table>
						<tr>
							<td class="input_title">Select League: </td>
							<td>
								<select class="selectElem" id="league_id">
									<option value="NULL">Select League</option>
									<?php
										//Populate the valid leagues
										$query    = "SELECT * FROM LEAGUES";
										$l_ids    = array();
										$l_names  = array();
										$results  = do_query($query, $g_db_name, $g_username);

                                        // Loop to store all of the league names and ids from the database
										// If the current date is less than that of the draft date for a league,
										// then display that league as a possible league to join, else do not
										// display it
										while ($row = mysql_fetch_assoc($results)){
											$id   = $row['LEAGUE_ID'];
											$name = $row['LEAGUE_NAME'];
											$dd = strtotime($row['DRAFT_DATE']);
											$today = strtotime("now");
											if ($dd > $today)
												echo "<option value='{$id}'>{$name}</option>";
										}
									?>
								</select>
							</td>
							<td></td>
						</tr>
						<tr>
                            <td class="input_title">League Password: </td>
							<td>
								<input type="password" class="resets" id="league_password" maxlength="25" size="12" />
							</td>
							<td></td>
						</tr>
					</table>
				</div>
				<h2>Team Information</h2>
				<div id="info_box">
					<table>
						<tr>
							<td class="input_title">Team Name: </td>
							<td class="input_value"><input class="resets" id="team_name" maxlength="32" size="30" onkeydown="keyPress(event);" /></td>
							<td></td>
						</tr>
						</div>
							<td class="input_title">Team Password: </td>
							<td class="input_value"><input type="password" class="resets" id="team_password" maxlength="16" size="30" onkeydown="keyPress(event);" /></td>
							<td></td>
						</tr>
						<tr>
							<td class="input_title">Confirm Password: </td>
							<td class="input_value"><input type="password" class="resets" id="team_password_confirm" maxlength="16" size="30" onkeydown="keyPress(event);" /></td>
							<td></td>
						</tr>
						<tr>
							<td class="input_title">Owner's Email: </td>
							<td class="input_value"><input id="team_email" class="resets" maxlength="64" size="30" onkeydown="keyPressEmail(event);" /></td>
							<td><i></i></td>
						</tr>
						<tr>
							<td class="input_title">Security Question: </td>
							<td class="input_value"><input id="team_question" class="resets" maxlength="255" size="30" onkeydown="keyPress(event);" /></td>
							<td><i></i></td>
						</tr>
						<tr>
							<td class="input_title">Security Answer: </td>
							<td class="input_value"><input id="team_answer" class="resets" maxlength="255" size="30" onkeydown="keyPress(event);" /></td>
							<td><i></i></td>
						</tr>
						<tr>
						    <td class="input_title">Upload Team Logo? </td>
						    <td>
                                <form name="upload_form">
                                    <input type="radio" name="upload_image" value="Yes"> Yes<br> <input type="radio" name="upload_image" checked="checked" value="No"> No
                                </form>
						    </td>
						    <input type='hidden' id='team_verify' value='empty'>
						    <td></td>
					    </tr>
                        <tr>
                            <td class="input_title"><?php echo $image_name ?></td>
                            <td class="input_value">
                                <?php echo $upload_status ?>
                            </td>
                            <td>
                                <?php 
                                    if ($image_name != 0) {
                                        echo "<img src='images/$image_name' height='32' width='32'>";
                                    }
                                ?>
                            </td>
                        </tr>
				    </table>
			    </div>
			    <div class="create_team_header">
				    <input type="button" id="submit_create" value="Create Team" onclick="checkCreateTeamFields();" />
			    </div>
			    <h2></h2>
		    </div>
    
			<div id="footer">
				<?php echo "$footer"; ?>
			</div>
		</div>
	</div>
</body>
</html>
